package agents;

import jade.content.lang.sl.SLCodec;
import jade.core.Agent;
import jade.core.Profile;
import jade.core.ProfileImpl;
import jade.domain.mobility.MobilityOntology;
import jade.wrapper.ContainerController;
import jade.wrapper.StaleProxyException;

@SuppressWarnings("serial")
public class BootAgent extends Agent {

	// Get a JADE Runtime instance
	jade.core.Runtime runtime = jade.core.Runtime.instance();

	private ContainerController container_hm = null;
	private ContainerController container_galileo = null;
	private ContainerController container_auctioneer = null;

	@Override
	protected void setup() {
		System.out.println(this.getLocalName() + ": Running setup()");

		// Register language and ontology
		getContentManager().registerLanguage(new SLCodec());
		getContentManager().registerOntology(MobilityOntology.getInstance());
		
		// Create containers	
		ProfileImpl prof_hm = new ProfileImpl();
		prof_hm.setParameter(Profile.CONTAINER_NAME, "Container_hm");
		container_hm = runtime.createAgentContainer(prof_hm);
		
		ProfileImpl prof_galileo = new ProfileImpl();
		prof_galileo.setParameter(Profile.CONTAINER_NAME, "Container_galileo");
		container_galileo = runtime.createAgentContainer(prof_galileo);
		
		ProfileImpl prof_auctioneer = new ProfileImpl();
		prof_auctioneer.setParameter(Profile.CONTAINER_NAME, "Container_auctionneer");
		container_auctioneer = runtime.createAgentContainer(prof_auctioneer);

		// Create agents
		try {
			container_auctioneer.createNewAgent("Auctioneer", AuctioneerAgent.class.getName(), null).start();
			container_hm.createNewAgent("Participant_hm", ParticipantAgent.class.getName(), null).start();
			container_galileo.createNewAgent("Participant_galileo", ParticipantAgent.class.getName(), null).start();
		} catch (StaleProxyException e) {
			// Should not happen
			e.printStackTrace();
		}

	}
}
